package org.example.controller;

import org.example.service.api.DormitoryServiceApi;
import org.example.util.JSONResult;
import org.example.util.JSONStats;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 寝室信息相关操作
 */

@Controller
@ResponseBody
@CrossOrigin
public class DormitoryTbController {
    //创建寝室服务对象
    @Autowired
    DormitoryServiceApi dormitoryService;


    /**
     * 寝室信息是否存在
     * @param dormitorynname 寝室名字
     * @return
     */
    @GetMapping("/checkDormitoryName")
    public JSONResult checkDormitoryName(String dormitorynname){
        //寝室信息检查
        if(dormitorynname!=null){
            //如果不为空 调用 service
            //小心是传入时参数传错了
            JSONResult jsonResult =dormitoryService.checkDormitoryName(dormitorynname);
            return jsonResult;
        }else {
            JSONResult jsonResult = new JSONResult();
            //失败的情况下
            jsonResult.setStatusCode(JSONStats.CHECK_DORMITORY_NAME_ERROR.getStatusCode());
            jsonResult.setMessage(JSONStats.CHECK_DORMITORY_NAME_ERROR.getMessage());
            return jsonResult;
        }
    }

    /**
     * 用户充值
     * @param userid 用户id
     * @param usermonkey 用户充值金额
     * @param dormitoryid 用户id
     * @return
     */

    @GetMapping("/despoitMonkey")
    public JSONResult userDepositMonkey(Integer userid,Integer usermonkey,Integer dormitoryid){



        if(userid>0 && usermonkey>0 && dormitoryid>0){
            //调用服务层

            JSONResult jsonResult=dormitoryService.depositMonkey(userid,usermonkey,dormitoryid);
            return  jsonResult;
        }else {
            //失败
            JSONResult jsonResult = new JSONResult();
            jsonResult.setStatusCode(JSONStats.DESPOIT_MONKEY_ERROR.getStatusCode());
            jsonResult.setMessage(JSONStats.DESPOIT_MONKEY_ERROR.getMessage());
            return jsonResult;

        }
    }
//增加寝室信息
    @GetMapping("/addDormitoryInfo")
    public JSONResult adminAddDormitoryInfo(String dormitoryName,Integer dormitoryFee){
        JSONResult jsonResult=dormitoryService.adminAddDormitoryInfo(dormitoryName,dormitoryFee);
        return jsonResult;
    }
//修改信息信息
    @GetMapping("/alterDormitory")
    public JSONResult adminALterDormitoryInfo(String dormitoryname,Integer dormitorymonkey,Integer dormitoryid){
        JSONResult jsonResult=dormitoryService.adminAlterDormitoryInfo(dormitoryname,dormitorymonkey,dormitoryid);
        return jsonResult;
    }
//删除寝室信息
    @GetMapping("/deleteDormitoryInfo")
    public JSONResult adminDeleteDormitoryInfo(String dormitoryname){
        JSONResult jsonResult=dormitoryService.adminDeleteDormitoryInfo(dormitoryname);
        return jsonResult;
    }
}
